﻿package cn.java.dsj158_a.util;

import java.util.List;

public class PageBean<T> {
	/* 当前页 */
	private Integer currentPage = 1;
	/* 每页显示条数 */
	private Integer pageSize = 1;
	/* 总条数 */
	private Integer totalCount;
	/* 总页数 */
	private Integer totalPage;
	/* 索引下标 */
	private Integer startIndex;
	private List<T> list;

	public Integer getCurrentPage() {
		return currentPage;
	}

	/**
	 * 当前页不能大于总页数,也不能小于1
	 * 
	 * @param currentPage
	 */
	public void setCurrentPage(Integer currentPage) {
		if (currentPage < 1) {
			this.currentPage = 1;
		} else if (currentPage >= totalPage) {
			this.currentPage = totalPage;
		} else {
			this.currentPage = currentPage;
		}

	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Integer getTotalCount() {
		return totalCount;
	}

	/**
	 * 只有总条数大于或等于0的时候才给赋值
	 * 
	 * @param totalCount
	 */
	public void setTotalCount(Integer totalCount) {
		if (totalCount >= 0) {
			this.totalCount = totalCount;
			/*赋值以后直接计算出总页数 this.totalPage */
			this.totalPage = (this.totalCount%this.pageSize) == 0?this.totalCount/this.pageSize:this.totalCount/this.pageSize+1;
		}
	}

	public Integer getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(Integer totalPage) {
		if (totalPage < 1) {
			this.totalPage = 1;
		}
		this.totalPage = totalPage;
	}

	public Integer getStartIndex() {
		return startIndex;
	}

	public void setStartIndex(Integer startIndex) {
		this.startIndex = startIndex;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

	@Override
	public String toString() {
		return "PageBean [currentPage=" + currentPage + ", pageSize="
				+ pageSize + ", totalCount=" + totalCount + ", totalPage="
				+ totalPage + ", startIndex=" + startIndex + ", list=" + list
				+ "]";
	}

}
